home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / stackvec.cls < prev    next >
Text File  |  1997-06-14  |  1KB  |  52 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CStackVec"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. Implements IStack
  13.  
  14. Private av() As Variant
  15. Private Const cChunk = 10
  16. Private iLast As Long, iCur As Long
  17.  
  18. Private Sub IStack_Push(vArg As Variant)
  19.     iCur = iCur + 1
  20.     On Error GoTo FailPush
  21.     If IsObject(vArg) Then
  22.         Set av(iCur) = vArg
  23.     Else
  24.         av(iCur) = vArg
  25.     End If
  26.     Exit Sub
  27. FailPush:
  28.     iLast = iLast + cChunk  ' Grow
  29.     ReDim Preserve av(1 To iLast) As Variant
  30.     Resume                  ' Try again
  31. End Sub
  32.  
  33. Private Function IStack_Pop() As Variant
  34.     If iCur Then
  35.         If IsObject(av(iCur)) Then
  36.             Set IStack_Pop = av(iCur)
  37.         Else
  38.             IStack_Pop = av(iCur)
  39.         End If
  40.         iCur = iCur - 1
  41.         If iCur < (iLast - cChunk) Then
  42.             iLast = iLast - cChunk      ' Shrink
  43.             ReDim Preserve av(1 To iLast) As Variant
  44.         End If
  45.     End If
  46. End Function
  47.  
  48. Private Property Get IStack_Count() As Long
  49.     IStack_Count = iCur
  50. End Property
  51. '
  52.